#include "SceneTask.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "deprecated/CCDeprecated.h"
#include "ui/UIHelper.h"
#include "base/CCConsole.h"
#include "logic/LLogicMap.h"
#include "logic/LLogicTask.h"

USING_NS_CC;
using namespace ui;

CSceneTask::CSceneTask(void)
{
}


CSceneTask::~CSceneTask(void)
{
}

bool CSceneTask::init() {
	// 1. super init first
    if ( !CSceneBase::init() )
    {
        return false;
    }
    
	//m_LoginNode = CSLoader::createNode("TaskScene.csb");
	
	//ui::Button* tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_LoginNode, 93);
	//tLoginB->addTouchEventListener(this, toucheventselector(CSceneTask::onLogin));

    //addChild(m_LoginNode);

    return true;
}

void CSceneTask::onEnter() {
	cocos2d::Scene::onEnter();

	m_NodeTask = CSLoader::createNode("TaskScene.csb");
	m_Close = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_NodeTask, 61);
	m_Close->addTouchEventListener(this, toucheventselector(CSceneTask::onClose));

	m_Group = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_NodeTask, 57);
	m_Group->addTouchEventListener(this, toucheventselector(CSceneTask::onGroup));

	m_GetTask = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_NodeTask, 60);
	m_GetTask->addTouchEventListener(this, toucheventselector(CSceneTask::onGetTask));

	m_TaskList = (cocos2d::ui::ListView*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_NodeTask, 59);

	addChild(m_NodeTask);
}

/*
void CSceneTask::onExit() {
	cocos2d::Scene::onExit();
}

void CSceneTask::update(float delta) {
	cocos2d::Scene::update(delta);
}
*/

/*
void CSceneTask:::onOpenPack(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type)
	{
	case cocos2d::ui::TOUCH_EVENT_ENDED:
		
		break;
	}
}*/

void CSceneTask::onClose(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type)
	{
	case cocos2d::ui::TOUCH_EVENT_ENDED:
		m_SceneManager->popScene();
		CLLogicMap tMap;
		tMap.LeaveMap(GLSLTMapTask);
		break;
	}
}

void CSceneTask::onGroup(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type)
	{
	case cocos2d::ui::TOUCH_EVENT_ENDED:
		cocos2d::Node* tGroupLayer = CCommonUiManager::GetInstance()->GetCommonNode(CCommonUiManager::CGroupIndex);
		tGroupLayer->setPosition(30,30);
		tGroupLayer->setVisible(true);
		addChild(tGroupLayer);
		break;
	}
}

void CSceneTask::onGetTask(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type)
	{
	case cocos2d::ui::TOUCH_EVENT_ENDED:
		CTLLogicTask tTask;
		tTask.XuanshangGet();
		break;
	}
}
